home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_097 / shm / shm_parameters.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  17KB  |  479 lines

  1. /************************************************************************
  2.                          Parameter Requester                  2 August 87
  3. ************************************************************************/
  4. #include <exec/types.h>
  5. #include <intuition/intuition.h>
  6.  
  7. #include "shm_defines"
  8.  
  9. extern int hc,hcd,vc,vcd,hs,hsd,vs,vsd;
  10. extern double hpp,hppd,vpp,vppd,hsp,hspd,vsp,vspd,di,did,sf,sfd,cp,cpd;
  11.  
  12. extern struct TextAttr Fnt;
  13.  
  14. /************************************************************************
  15.                           Parameter Definitions
  16. ************************************************************************/
  17. char horiz_centre_str[6],    vert_centre_str[6],
  18.      horiz_size_str[6],      vert_size_str[6],
  19.      horiz_pri_phase_str[6], vert_pri_phase_str[6],
  20.      horiz_sec_phase_str[6], vert_sec_phase_str[6],
  21.      decay_str[6],     freq_str[6],    coup_str[6];
  22.  
  23. struct IntuiText parms_txt =  {1, 0, JAM1, 132, 3, &Fnt,
  24.                               (UBYTE *)"PARAMETER SETTINGS", NL};
  25. struct IntuiText horiz_txt =  {1, 0, JAM1, 65, 14, &Fnt,
  26.                               (UBYTE *)"Horizontal", &parms_txt};
  27. struct IntuiText vert_txt  =  {1, 0, JAM1, 263, 14, &Fnt,
  28.                               (UBYTE *)"Vertical", &horiz_txt};
  29. struct IntuiText centre_txt = {1, 0, JAM1, 177, 27, &Fnt,
  30.                               (UBYTE *)"CENTRE", &vert_txt};
  31. struct IntuiText size_txt   = {1, 0, JAM1, 183, 41, &Fnt,
  32.                               (UBYTE *)"SIZE", ¢re_txt};
  33. struct IntuiText pri_txt    = {1, 0, JAM1, 171, 53, &Fnt,
  34.                               (UBYTE *)"Primary", &size_txt};
  35. struct IntuiText phase_txt  = {1, 0, JAM1, 180, 63, &Fnt,
  36.                               (UBYTE *)"PHASE", &pri_txt};
  37. struct IntuiText sec_txt    = {1, 0, JAM1, 164, 71, &Fnt,
  38.                               (UBYTE *)"Secondary", &phase_txt};
  39. struct IntuiText decay_txt  = {1, 0, JAM1, 164, 84, &Fnt,
  40.                               (UBYTE *)"DECAY", &sec_txt};
  41. struct IntuiText freq_txt   = {1, 0, JAM1, 164, 98, &Fnt,
  42.                               (UBYTE *)"FREQUENCY", &decay_txt};
  43. struct IntuiText coup_txt   = {1, 0, JAM1, 164, 112, &Fnt,
  44.                               (UBYTE *)"COUPLING", &freq_txt};
  45. struct IntuiText horiz_centre_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  46.                               (UBYTE *)horiz_centre_str, NL};
  47. struct IntuiText vert_centre_val_txt  = {1, 3, JAM2, 114, 2, &Fnt,
  48.                               (UBYTE *)vert_centre_str, NL};
  49. struct IntuiText horiz_size_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  50.                               (UBYTE *)horiz_size_str, NL};
  51. struct IntuiText vert_size_val_txt  = {1, 3, JAM2, 114, 2, &Fnt,
  52.                               (UBYTE *)vert_size_str, NL};
  53. struct IntuiText horiz_pri_phase_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  54.                               (UBYTE *)horiz_pri_phase_str, NL};
  55. struct IntuiText vert_pri_phase_val_txt  = {1, 3, JAM2, 114, 2, &Fnt,
  56.                               (UBYTE *)vert_pri_phase_str, NL};
  57. struct IntuiText horiz_sec_phase_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  58.                               (UBYTE *)horiz_sec_phase_str, NL};
  59. struct IntuiText vert_sec_phase_val_txt  = {1, 3, JAM2, 114, 2, &Fnt,
  60.                               (UBYTE *)vert_sec_phase_str, NL};
  61. struct IntuiText decay_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  62.                               (UBYTE *)decay_str, NL};
  63. struct IntuiText freq_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  64.                               (UBYTE *)freq_str, NL};
  65. struct IntuiText coup_val_txt  = {1, 3, JAM2, -44, 2, &Fnt,
  66.                               (UBYTE *)coup_str, NL};
  67.  
  68. /************************* Parameter Switches *************************/
  69.  
  70. struct Image parm_gad_img = {0,0, 154,11, 1, NL, 0, 2, NL};
  71.  
  72. struct IntuiText parm_cancel_txt = {3, 0, JAM1, 55, 2, &Fnt,
  73.                                    (UBYTE *)"Cancel", NL};
  74. struct Gadget parm_cancel_gad =
  75. {
  76. NL,
  77. 240, 84, 154, 11,
  78. GADGHBOX | GADGIMAGE,
  79. RELVERIFY,
  80. BOOLGADGET | REQGADGET,
  81. (APTR)&parm_gad_img, NL,
  82. &parm_cancel_txt,
  83. NL, NL, 1, NL
  84. };
  85.  
  86. struct IntuiText parm_def_txt    = {3, 0, JAM1, 47, 2, &Fnt,
  87.                                    (UBYTE *)"Default ", NL};
  88. struct Gadget parm_def_gad =
  89. {
  90. &parm_cancel_gad,
  91. 240, 97, 154, 11,
  92. GADGHBOX | GADGIMAGE,
  93. RELVERIFY,
  94. BOOLGADGET | REQGADGET,
  95. (APTR)&parm_gad_img, NL,
  96. &parm_def_txt,
  97. NL, NL, 2, NL
  98. };
  99.  
  100. struct IntuiText parm_ok_txt     = {3, 0, JAM1, 67, 2, &Fnt,
  101.                                    (UBYTE *)"OK", NL};
  102. struct Gadget parm_ok_gad =
  103. {
  104. &parm_def_gad,
  105. 240, 110, 154, 11,
  106. GADGHBOX | GADGIMAGE,
  107. RELVERIFY | ENDGADGET,
  108. BOOLGADGET | REQGADGET,
  109. (APTR)&parm_gad_img, NL,
  110. &parm_ok_txt,
  111. NL, NL, 3, NL
  112. };
  113. /************************* Parameter Sliders **************************/
  114.  
  115. struct Image horiz_centre_image, vert_centre_image,
  116.              horiz_size_image, vert_size_image,
  117.              horiz_pri_phase_image, vert_pri_phase_image,
  118.              horiz_sec_phase_image, vert_sec_phase_image,
  119.              decay_image, freq_image, coup_image;
  120.  
  121. struct PropInfo horiz_centre_prop, vert_centre_prop,
  122.                 horiz_size_prop, vert_size_prop,
  123.                 horiz_pri_phase_prop, vert_pri_phase_prop,
  124.                 horiz_sec_phase_prop, vert_sec_phase_prop,
  125.                 decay_prop, freq_prop, coup_prop;
  126.  
  127. struct Gadget horiz_centre_gad =
  128. {
  129. &parm_ok_gad,
  130. 50, 25, 110, 11,
  131. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  132. (APTR)&horiz_centre_image, NL,
  133. &horiz_centre_val_txt, NL,
  134. (APTR)&horiz_centre_prop,
  135. 4, NL
  136. };
  137.  
  138. struct Gadget vert_centre_gad =
  139. {
  140. &horiz_centre_gad,
  141. 240, 25, 110, 11,
  142. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  143. (APTR)&vert_centre_image, NL,
  144. &vert_centre_val_txt, NL,
  145. (APTR)&vert_centre_prop,
  146. 5, NL
  147. };
  148.  
  149. struct Gadget horiz_size_gad =
  150. {
  151. &vert_centre_gad,
  152. 50, 39, 110, 11,
  153. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  154. (APTR)&horiz_size_image, NL,
  155. &horiz_size_val_txt, NL,
  156. (APTR)&horiz_size_prop,
  157. 6, NL
  158. };
  159.  
  160. struct Gadget vert_size_gad =
  161. {
  162. &horiz_size_gad,
  163. 240, 39, 110, 11,
  164. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  165. (APTR)&vert_size_image, NL,
  166. &vert_size_val_txt, NL,
  167. (APTR)&vert_size_prop,
  168. 7, NL
  169. };
  170.  
  171. struct Gadget horiz_pri_phase_gad =
  172. {
  173. &vert_size_gad,
  174. 50, 53, 110, 11,
  175. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  176. (APTR)&horiz_pri_phase_image, NL,
  177. &horiz_pri_phase_val_txt, NL,
  178. (APTR)&horiz_pri_phase_prop,
  179. 8, NL
  180. };
  181.  
  182. struct Gadget vert_pri_phase_gad =
  183. {
  184. &horiz_pri_phase_gad,
  185. 240, 53, 110, 11,
  186. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  187. (APTR)&vert_pri_phase_image, NL,
  188. &vert_pri_phase_val_txt, NL,
  189. (APTR)&vert_pri_phase_prop,
  190. 9, NL
  191. };
  192.  
  193. struct Gadget horiz_sec_phase_gad =
  194. {
  195. &vert_pri_phase_gad,
  196. 50, 67, 110, 11,
  197. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  198. (APTR)&horiz_sec_phase_image, NL,
  199. &horiz_sec_phase_val_txt, NL,
  200. (APTR)&horiz_sec_phase_prop,
  201. 10, NL
  202. };
  203.  
  204. struct Gadget vert_sec_phase_gad =
  205. {
  206. &horiz_sec_phase_gad,
  207. 240, 67, 110, 11,
  208. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  209. (APTR)&vert_sec_phase_image, NL,
  210. &vert_sec_phase_val_txt, NL,
  211. (APTR)&vert_sec_phase_prop,
  212. 11, NL
  213. };
  214.  
  215. struct Gadget decay_gad =
  216. {
  217. &vert_sec_phase_gad,
  218. 50, 82, 110, 11,
  219. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  220. (APTR)&decay_image, NL,
  221. &decay_val_txt, NL,
  222. (APTR)&decay_prop,
  223. 12, NL
  224. };
  225.  
  226. struct Gadget freq_gad =
  227. {
  228. &decay_gad,
  229. 50, 96, 110, 11,
  230. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  231. (APTR)&freq_image, NL,
  232. &freq_val_txt, NL,
  233. (APTR)&freq_prop,
  234. 13, NL
  235. };
  236.  
  237. struct Gadget coup_gad =
  238. {
  239. &freq_gad,
  240. 50, 110, 110, 11,
  241. GADGHCOMP, GADGIMMEDIATE | RELVERIFY, PROPGADGET | REQGADGET,
  242. (APTR)&coup_image, NL,
  243. &coup_val_txt, NL,
  244. (APTR)&coup_prop,
  245. 14, NL
  246. };
  247.  
  248. #define PMX 400    /* Parameter requester size */
  249. #define PMY 124
  250.  
  251. struct Requester parms_req;
  252.  
  253. SHORT parms_border_coords[] = {0,0, PMX-1,0, PMX-1,PMY-1, 0,PMY-1, 0,0};
  254.  
  255. struct Border parms_border =
  256. {
  257. 0,0,
  258. 1,0,JAM1,
  259. 5,&parms_border_coords[0],
  260. NL
  261. };
  262.  
  263. /************************************************************************
  264.                      Initialise Parameter Sliders
  265. ************************************************************************/ 
  266. void init_parm_sliders(cW)
  267. struct Window *cW;
  268. {
  269. horiz_centre_prop.HorizPot = (int) (65535*hc)/XMAX;
  270. vert_centre_prop.HorizPot  = (int) (65535*vc)/YMAX;
  271. horiz_size_prop.HorizPot   = (int) (65535*hs)/XMAX;
  272. vert_size_prop.HorizPot    = (int) (65535*vs)/YMAX;
  273. horiz_pri_phase_prop.HorizPot = (int) (65535*hpp)/TWOPI;
  274. vert_pri_phase_prop.HorizPot  = (int) (65535*vpp)/TWOPI;
  275. horiz_sec_phase_prop.HorizPot = (int) (65535*hsp)/TWOPI;
  276. vert_sec_phase_prop.HorizPot  = (int) (65535*vsp)/TWOPI;
  277. decay_prop.HorizPot = (int) (65535*di)/DMAX;
  278. freq_prop.HorizPot  = (int) (65535*sf)/FMAX;
  279. coup_prop.HorizPot  = (int) (65535*cp)/CMAX;
  280.  
  281. sprintf(horiz_centre_str,"%5d\0",hc);
  282. sprintf(vert_centre_str,"%-5d\0",vc);
  283. sprintf(horiz_size_str,"%5d\0",hs);
  284. sprintf(vert_size_str,"%-5d\0",vs);
  285. sprintf(horiz_pri_phase_str,"%5.3f\0",hpp);
  286. sprintf(vert_pri_phase_str,"%5.3f\0",vpp);
  287. sprintf(horiz_sec_phase_str,"%5.3f\0",hsp);
  288. sprintf(vert_sec_phase_str,"%5.3f\0",vsp);
  289. sprintf(decay_str,"%5.3f\0",di*TWOPI/DT);
  290. sprintf(freq_str,"%5.3f\0",sf);
  291. sprintf(coup_str,"%5.3f\0",cp);
  292.  
  293. RefreshGadgets(&coup_gad,cW,NL);
  294. }
  295. /************************************************************************
  296.                           Parameter Function
  297. ************************************************************************/ 
  298. parms(cW)
  299. struct Window *cW;
  300. {
  301. FAST struct IntuiMessage *message;
  302. FAST int class,item;
  303. int hcb,vcb,hsb,vsb;                       /* backup parameters */
  304. int hct,vct,hst,vst;                       /* temporary values  */
  305. double hppb,vppb,hspb,vspb,dib,sfb,cpb;    /* backup parameters */
  306. double hppt,vppt,hspt,vspt,dit,sft,cpt;    /* temporary values  */
  307. BOOL loop;
  308.  
  309. hct = hcb = hc; vct = vcb = vc; hst = hsb = hs; vst = vsb = vs;
  310. hppt = hppb = hpp; vppt = vppb = vpp;
  311. hspt = hspb = hsp; vspt = vspb = vsp;
  312. dit = dib = di; sft = sfb = sf; cpt = cpb = cp;
  313.  
  314. horiz_centre_prop.Flags    = vert_centre_prop.Flags = 
  315. horiz_size_prop.Flags      = vert_size_prop.Flags = 
  316. horiz_pri_phase_prop.Flags = vert_pri_phase_prop.Flags = 
  317. horiz_sec_phase_prop.Flags = vert_sec_phase_prop.Flags = 
  318. decay_prop.Flags           = freq_prop.Flags = 
  319. coup_prop.Flags            = FREEHORIZ | AUTOKNOB;
  320.  
  321. horiz_centre_prop.HorizBody    = vert_centre_prop.HorizBody = 
  322. horiz_size_prop.HorizBody      = vert_size_prop.HorizBody = 
  323. horiz_pri_phase_prop.HorizBody = vert_pri_phase_prop.HorizBody = 
  324. horiz_sec_phase_prop.HorizBody = vert_sec_phase_prop.HorizBody = 
  325. decay_prop.HorizBody           = freq_prop.HorizBody = 
  326. coup_prop.HorizBody            = 0x1000;
  327.  
  328. ModifyIDCMP(cW,GADGETUP | GADGETDOWN | REQCLEAR | MOUSEMOVE);
  329.  
  330.          /* Remember to set REPORTMOUSE flag in window structure
  331.                                            for MOUSEMOVE to work */
  332. InitRequester(&parms_req);
  333. parms_req.LeftEdge = 120;
  334. parms_req.TopEdge = 25;
  335. parms_req.Width = PMX;
  336. parms_req.Height = PMY;
  337. parms_req.ReqGadget = &coup_gad;
  338. parms_req.ReqText = &coup_txt;
  339. parms_req.BackFill = 3;
  340. parms_req.ReqBorder = &parms_border;
  341. Request(&parms_req,cW);
  342.  
  343. init_parm_sliders(cW);
  344.  
  345. loop=TRUE;
  346.  
  347. while (loop)
  348.       {
  349.       Wait(1 << cW->UserPort->mp_SigBit); /* Be good and go to sleep till
  350.                                              Intuition sends a message */
  351.  
  352.       while (message=(struct IntuiMessage *) GetMsg(cW->UserPort))
  353.          {
  354.          class = message->Class;   /* Process all outstanding Messages */
  355.          ReplyMsg(message);
  356.  
  357.          if (class == REQCLEAR) loop = FALSE;           /* OK Selected */
  358.  
  359.          if ((class == GADGETDOWN) || (class == GADGETUP))
  360.             item = ((struct Gadget *) message->IAddress)->GadgetID;
  361.                              /* Get GadgetID for sliders on GADGETDOWN
  362.                                              and Booleans on GADGETDUP */
  363.  
  364.          /* MOUSEMOVE events are not acknowledged specifically, but by
  365.             generating a message cause the following code for cases >3
  366.             to update the sliders */
  367.          }
  368.       switch (item)
  369.              {
  370.              case 1 : hc = hcb; vc = vcb; hs = hsb; vs = vsb;
  371.                       hpp = hppb; vpp = vppb; hsp = hspb; vsp = vspb;
  372.                       di = dib; sf = sfb; cp = cpb;
  373.                       init_parm_sliders(cW);             /* Cancel */
  374.                       item = 0;
  375.                       break;
  376.              case 2 : hc = hcd; vc = vcd; hs = hsd; vs = vsd;
  377.                       hpp = hppd; vpp = vppd; hsp = hspd; vsp = vspd;
  378.                       di = did; sf = sfd; cp = cpd;
  379.                       init_parm_sliders(cW);            /* Default */
  380.                       item = 0;
  381.                       break;
  382.              case 4 : /* Update slider only if the value has changed */
  383.                       hct = (int) (XMAX*horiz_centre_prop.HorizPot)/65535;
  384.                       if (hct != hc)
  385.                          {
  386.                          hc = hct;
  387.                          sprintf(horiz_centre_str,"%5d\0",hc);
  388.                          RefreshGList(&horiz_centre_gad,cW,&parms_req,1);
  389.                          } 
  390.                       break;
  391.              case 5 : vct = (int) (YMAX*vert_centre_prop.HorizPot)/65535;
  392.                       if (vct != vc)
  393.                          {
  394.                          vc = vct;
  395.                          sprintf(vert_centre_str,"%-5d\0",vc);
  396.                          RefreshGList(&vert_centre_gad,cW,&parms_req,1);
  397.                          }
  398.                       break;
  399.              case 6 : hst = (int) (XMAX*horiz_size_prop.HorizPot)/65535;
  400.                       if (hst != hs)
  401.                          {
  402.                          hs = hst; 
  403.                          sprintf(horiz_size_str,"%5d\0",hs);
  404.                          RefreshGList(&horiz_size_gad,cW,&parms_req,1);
  405.                          }
  406.                       break;
  407.              case 7 : vst = (int) (YMAX*vert_size_prop.HorizPot)/65535;
  408.                       if (vst != vs)
  409.                          {
  410.                          vs = vst;
  411.                          sprintf(vert_size_str,"%-5d\0",vs);
  412.                          RefreshGList(&vert_size_gad,cW,&parms_req,1);
  413.                          }
  414.                       break;
  415.              case 8 : hppt = (double)
  416.                              (TWOPI*horiz_pri_phase_prop.HorizPot)/65535;
  417.                       if (hppt != hpp)
  418.                          {
  419.                          hpp = hppt;
  420.                          sprintf(horiz_pri_phase_str,"%5.3f\0",hpp);
  421.                          RefreshGList(&horiz_pri_phase_gad,cW,&parms_req,1);
  422.                          }
  423.                       break;
  424.              case 9 : vppt = (double)
  425.                              (TWOPI*vert_pri_phase_prop.HorizPot)/65535;
  426.                       if (vppt != vpp)
  427.                          {
  428.                          vpp = vppt;
  429.                          sprintf(vert_pri_phase_str,"%5.3f\0",vpp);
  430.                          RefreshGList(&vert_pri_phase_gad,cW,&parms_req,1);
  431.                          }
  432.                       break;
  433.              case 10 : hspt = (double)
  434.                               (TWOPI*horiz_sec_phase_prop.HorizPot)/65535;
  435.                        if (hspt != hsp)
  436.                           {
  437.                           hsp = hspt;
  438.                           sprintf(horiz_sec_phase_str,"%5.3f\0",hsp);
  439.                           RefreshGList(&horiz_sec_phase_gad,cW,&parms_req,1);
  440.                           }
  441.                        break;
  442.              case 11 : vspt = (double)
  443.                               (TWOPI*vert_sec_phase_prop.HorizPot)/65535;
  444.                        if (vspt != vsp)
  445.                           {
  446.                           vsp = vspt;
  447.                           sprintf(vert_sec_phase_str,"%5.3f\0",vsp);
  448.                           RefreshGList(&vert_sec_phase_gad,cW,&parms_req,1);
  449.                           }
  450.                        break;
  451.              case 12 : dit = (double) (DMAX*decay_prop.HorizPot)/65535;
  452.                        if (dit != di)
  453.                           {
  454.                           di = dit;
  455.                           sprintf(decay_str,"%5.3f\0",di*TWOPI/DT);
  456.                           RefreshGList(&decay_gad,cW,&parms_req,1);
  457.                           }
  458.                        break;
  459.              case 13 : sft = (double) (FMAX*freq_prop.HorizPot)/65535;
  460.                        if (sft != sf)
  461.                           {
  462.                           sf = sft;
  463.                           sprintf(freq_str,"%5.3f\0",sf);
  464.                           RefreshGList(&freq_gad,cW,&parms_req,1);
  465.                           }
  466.                        break;
  467.              case 14 : cpt = (double) (CMAX*coup_prop.HorizPot)/65535;
  468.                        if (cpt != cp)
  469.                           {
  470.                           cp = cpt;
  471.                           sprintf(coup_str,"%5.3f\0",cp);
  472.                           RefreshGList(&coup_gad,cW,&parms_req,1);
  473.                           }
  474.              }
  475.       }
  476. ModifyIDCMP(cW,MENUPICK | ACTIVEWINDOW | REQCLEAR | INTUITICKS);
  477. return(TRUE);
  478. }
  479.